<include file="public@header" />
</head>

<body>
	<div class="wrap js-check-wrap">
		<ul class="nav nav-tabs">
			<?php $currentTab = 3 ;?>
			<include file="public/../company/nav" />
		</ul>
        <div style="padding: 10px 30px;">
            <input type="button" class="btn btn-primary" onclick="addCategory();" value="添加行业" />
        </div>
        
        <table class="table table-bordered" style="text-align: center;">
        	<thead>
        		<tr>
        			<th style="text-align: center;" >类别名称</th> 
        			<th style="text-align: center;" >创建时间</th>
        			<th style="text-align: center;" >操作</th>
        		</tr>
        	</thead>
        	<tbody>
                <volist name="list" id="vo">
        		<tr>
        			<td class="type_name" data-v={$vo.type_name} data-i={$vo.id}>{$vo.type_name}</td>
                    <td>{$vo.create_time|date="Y-m-d : H:i:s",###}</td>
                    <td><a href="javascript:;" onclick="editCategory(this);">编辑</a>|<a id="delete1" href="javascript:;" onclick="delCategory('{:url('company/del_type',['id'=>$vo.id])}');">删除</a></td>
        		</tr>
            </volist>
        	</tbody>
        </table>

	</div>
	<script src="__STATIC__/js/admin.js"></script>
    <script src="__STATIC__/js/layer/layer.js"></script>
<script>
    //添加行业分类方法
function addCategory()
{
    var s=$('#newtr');
    if(s.attr('id')=="newtr"){
        layer.alert('不能重复添加！');return false;
    }
    var tr='<tr id="newtr"><td><form class="js-ajax-form form-inline" action="{:url("company/add_type")}" method="post"><input type="text" name="type_name" class="form-control"  style="border:2px solid green;" placeholder="请输入类别名称"><button class="js-ajax-submit btn btn-success" type="submit" >保存</button> </form></td><td></td><td> <input type="button" class="btn btn-primary" onclick="removeCategory(this);" value="移除" /></td></tr>';
    $('tbody').prepend(tr);
}
//移除分类添加
function removeCategory(x)
{

    $(x).parent().parent().remove();
}

//编辑分类
function editCategory(e)
{
    var type_name=$(e).parent().parent().find('.type_name').data('v');
    var id=$(e).parent().parent().find('.type_name').data('i');
    var td='<form class="js-ajax-form form-inline" action="{:url("company/edit_type")}" method="post"><input type="hidden" name="id" value="'+id+'"/><input type="text" name="type_name" class="form-control"  style="border:2px solid green;" placeholder="请输入类别名称" value="'+type_name+'">&nbsp;&nbsp;<button class="js-ajax-submit btn btn-success" type="submit" >修改</button>&nbsp;&nbsp;<input onclick="cancelEditCategory(this);"  type="button" class="btn btn-primary" value="取消"> </form>';
    $(e).parent().parent().find('.type_name').html(td);
}
//取消分类编辑
function  cancelEditCategory(e)
{
    var type_name=$(e).parent().parent().parent().find('.type_name').data('v');
    $(e).parent().parent().parent().find('.type_name').html(type_name);
}

//删除分类
function delCategory(url)
{
    var index=layer.confirm('该分类如果被引用则无法删除，确定删除吗？', {
      btn: ['确定','取消'] //按钮
    }, function(){
      //提交请求
      $.get(url,function(data){
        layer.alert(data.msg);
        if(data.code==1){
            setTimeout(function () {
                    window.location.reload();
            }, 3000);
        }
      });
    }, function(){
      layer.close(index);
      layer.msg('操作已取消！');
    });
}
</script>
</body>
</html>